API: gdk: Add gdk_window_new_temp()
authorBenjamin Otte <otte@redhat.com>
Mon, 7 Nov 2016 00:03:17 +0000 (01:03 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 7 Nov 2016 00:03:17 +0000 (01:03 +0100)
Your one stop shop for all those nasty hidden input-only windows.

gdk/broadway/gdkwindow-broadway.c
gdk/gdkwindow.c
gdk/gdkwindow.h
gdk/x11/gdkdisplay-x11.c
gdk/x11/gdkwindow-x11.c
gtk/gtkinvisible.c
gtk/gtkmenu.c

index 596ed6d4dfbe95005347be0a780d20989f4469ec..c3c9adfa642382eb8aa7e4eb2e4239131eecedf1 100644 (file)
@@ -1290,28 +1290,13 @@ static void
 create_moveresize_window (MoveResizeData *mv_resize,
                          guint32         timestamp)
 {
-  GdkWindowAttr attributes;
-  gint attributes_mask;
   GdkGrabStatus status;
   GdkSeat *seat;
   GdkDevice *pointer;
 
   g_assert (mv_resize->moveresize_emulation_window == NULL);
 
-  attributes.x = -100;
-  attributes.y = -100;
-  attributes.width = 10;
-  attributes.height = 10;
-  attributes.window_type = GDK_WINDOW_TEMP;
-  attributes.wclass = GDK_INPUT_ONLY;
-  attributes.event_mask = 0;
-
-  attributes_mask = GDK_WA_X | GDK_WA_Y;
-
-  mv_resize->moveresize_emulation_window =
-    gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
-                   &attributes,
-                   attributes_mask);
+  mv_resize->moveresize_emulation_window = gdk_window_new_temp (mv_resize->display);
 
   gdk_window_show (mv_resize->moveresize_emulation_window);
 
index 0d7a6d6f850e62d17fb05f9482b2812262f1ffdd..0db6270f1f9afac2485644bb618668ca63d0957a 100644 (file)
@@ -1365,6 +1365,40 @@ gdk_window_new_popup (GdkDisplay         *display,
                          &attr,
                          GDK_WA_X | GDK_WA_Y);
 }
+
+/**
+ * gdk_window_new_temp: (constructor)
+ * @display: the display to create the window on
+ *
+ * Creates a new toplevel temporary window. The window will be
+ * situated off-screen and not handle output.
+ *
+ * You most likely do not want to use this function.
+ *
+ * Returns: (transfer full): the new #GdkWindow
+ *
+ * Since: 3.90
+ **/
+GdkWindow *
+gdk_window_new_temp (GdkDisplay *display)
+{
+  GdkWindowAttr attr;
+
+  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+
+  attr.event_mask = 0;
+  attr.wclass = GDK_INPUT_ONLY;
+  attr.x = -100;
+  attr.y = -100;
+  attr.width = 10;
+  attr.height = 10;
+  attr.window_type = GDK_WINDOW_TEMP;
+
+  return gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (display)),
+                         &attr,
+                         GDK_WA_X | GDK_WA_Y);
+}
+
 /**
  * gdk_window_new_child: (constructor)
  * @parent: the parent window
index 33c3d524088d50d232fbb0e19e5c3361a7cc59d9..83030a86a0d037dda3bd96495f01ac5df6fb6fa3 100644 (file)
@@ -475,6 +475,8 @@ GdkWindow *   gdk_window_new_popup             (GdkDisplay    *display,
                                                 gint           event_mask,
                                                 const GdkRectangle *position);
 GDK_AVAILABLE_IN_3_90
+GdkWindow *   gdk_window_new_temp              (GdkDisplay    *display);
+GDK_AVAILABLE_IN_3_90
 GdkWindow *   gdk_window_new_child             (GdkWindow     *parent,
                                                 gint           event_mask,
                                                 const GdkRectangle *position);
index 78845701289e8aad0dfc6aeddae88c629b14ae8f..cca0b651be77a28452584fea5aea02b8cd2ca7d5 100644 (file)
@@ -1356,7 +1356,6 @@ _gdk_x11_display_open (const gchar *display_name)
   Display *xdisplay;
   GdkDisplay *display;
   GdkX11Display *display_x11;
-  GdkWindowAttr attr;
   gint argc;
   gchar *argv[1];
 
@@ -1417,16 +1416,7 @@ _gdk_x11_display_open (const gchar *display_name)
 
   gdk_event_init (display);
 
-  attr.window_type = GDK_WINDOW_TOPLEVEL;
-  attr.wclass = GDK_INPUT_ONLY;
-  attr.x = 10;
-  attr.y = 10;
-  attr.width = 10;
-  attr.height = 10;
-  attr.event_mask = 0;
-
-  display_x11->leader_gdk_window = gdk_window_new (GDK_X11_SCREEN (display_x11->screen)->root_window, 
-                                                  &attr, GDK_WA_X | GDK_WA_Y);
+  display_x11->leader_gdk_window = gdk_window_new_temp (display);
   (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
 
   display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
index 8d226dca7444b92f0421af6e20b57628c0bd6041..371ba9e24682f852521b462a4c90d6d75aa9360a 100644 (file)
@@ -4815,27 +4815,11 @@ static void
 create_moveresize_window (MoveResizeData *mv_resize,
                           guint32         timestamp)
 {
-  GdkWindowAttr attributes;
-  gint attributes_mask;
   GdkGrabStatus status;
 
   g_assert (mv_resize->moveresize_emulation_window == NULL);
 
-  attributes.x = -100;
-  attributes.y = -100;
-  attributes.width = 10;
-  attributes.height = 10;
-  attributes.window_type = GDK_WINDOW_TEMP;
-  attributes.wclass = GDK_INPUT_ONLY;
-  attributes.event_mask = 0;
-
-  attributes_mask = GDK_WA_X | GDK_WA_Y;
-
-  mv_resize->moveresize_emulation_window = 
-    gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
-                   &attributes,
-                   attributes_mask);
-
+  mv_resize->moveresize_emulation_window = gdk_window_new_temp (mv_resize->display);
   gdk_window_show (mv_resize->moveresize_emulation_window);
 
   status = gdk_seat_grab (gdk_device_get_seat (mv_resize->device),
index ebea8b9d9bda152d37f2d61c0e1da4d16e6a1407..16f5ef695e83323870c2b32c33452dbbe36b72c7 100644 (file)
@@ -229,28 +229,11 @@ gtk_invisible_get_screen (GtkInvisible *invisible)
 static void
 gtk_invisible_realize (GtkWidget *widget)
 {
-  GdkWindow *parent;
   GdkWindow *window;
-  GdkWindowAttr attributes;
-  gint attributes_mask;
 
   gtk_widget_set_realized (widget, TRUE);
 
-  parent = gtk_widget_get_parent_window (widget);
-  if (parent == NULL)
-    parent = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
-
-  attributes.x = -100;
-  attributes.y = -100;
-  attributes.width = 10;
-  attributes.height = 10;
-  attributes.window_type = GDK_WINDOW_TEMP;
-  attributes.wclass = GDK_INPUT_ONLY;
-  attributes.event_mask = gtk_widget_get_events (widget);
-
-  attributes_mask = GDK_WA_X | GDK_WA_Y;
-
-  window = gdk_window_new (parent, &attributes, attributes_mask);
+  window = gdk_window_new_temp (gtk_widget_get_display (widget));
   gtk_widget_set_window (widget, window);
   gtk_widget_register_window (widget, window);
 }
index f7ac5b294b599d820c4e681f5002e0e275e2cd3d..e345779ff709cf940ef1b251828e725f94d1232f 100644 (file)
@@ -2667,23 +2667,7 @@ menu_grab_transfer_window_get (GtkMenu *menu)
   GdkWindow *window = g_object_get_data (G_OBJECT (menu), "gtk-menu-transfer-window");
   if (!window)
     {
-      GdkWindowAttr attributes;
-      gint attributes_mask;
-      GdkWindow *parent;
-
-      attributes.x = -100;
-      attributes.y = -100;
-      attributes.width = 10;
-      attributes.height = 10;
-      attributes.window_type = GDK_WINDOW_TEMP;
-      attributes.wclass = GDK_INPUT_ONLY;
-      attributes.event_mask = 0;
-
-      attributes_mask = GDK_WA_X | GDK_WA_Y;
-
-      parent = gdk_screen_get_root_window (gtk_widget_get_screen (GTK_WIDGET (menu)));
-      window = gdk_window_new (parent,
-                               &attributes, attributes_mask);
+      window = gdk_window_new_temp (gtk_widget_get_display (GTK_WIDGET (menu)));
       gtk_widget_register_window (GTK_WIDGET (menu), window);
 
       gdk_window_show (window);